// 院外医院--后结算--新建退货单
import { getFormatterPrice } from '@const/filter'
let vm = null
export const sendThis = (_this) => {
  vm = _this
}
// 后结算订单状态
// 订单状态（0-全部，11-待响应，12-待发货，13-发货完成，14-已完成，15-已撤消，16-已拒绝）
export const statusArr = {
  0: '全部',
  11: '待响应',
  12: '待发货',
  13: '发货完成',
  14: '已完成',
  15: '已撤销',
  16: '已拒绝'
}
// 退货类型
export const returnTypeOpt = [
  { value: 1, label: '批发采购质检退货' },
  { value: 2, label: '寄售采购质检退货' },
  { value: 3, label: '批发采购退货' },
  { value: 4, label: '寄售采购退货' }
]
export const redTicketOpt = [
  { value: 1, label: '是' },
  { value: 0, label: '否' }
]
const contactNumberPass = (rule, value, callback) => {
  // 手机号校验
  rule = /^1[3456789]\d{9}$/
  if (value === '') {
    callback(new Error('请输入手机号'))
  } else if (!rule.test(value)) {
    callback(new Error('请输入正确的手机号'))
  } else {
    callback()
  }
}
const contactCodePass = (rule, value, callback, source, options) => {
  if (value === '') {
    callback(new Error('输入不能为空'))
  } else if (!vm.baseInfo.deliveryCompanyId) {
    callback(new Error('请选择配送商'))
  } else {
    callback()
  }
}
// 编辑表单字段
export const baseColumns = [
  {
    prop: 'deliveryCompanyName',
    label: '配送商',
    type: 'select',
    options: [],
    optionValue: 'companyName',
    optionLabel: 'companyName',
    attr: {
      placeholder: '请选择',
      filterable: true
    },
    rules: [
      { required: true, message: '请选择配送商', trigger: 'change' }
    ]
  },
  {
    prop: 'orderType',
    label: '退货类型',
    type: 'select',
    options: returnTypeOpt,
    attr: {
      placeholder: '请选择'
    },
    rules: [
      { required: true, message: '请选择退货类型', trigger: 'change' }
    ]
  },
  {
    prop: 'deliveryOrderCode',
    label: '发货单号',
    type: 'select',
    options: [],
    optionValue: 'deliveryCode',
    optionLabel: 'deliveryCode',
    attr: {
      filterable: true,
      clearable: true,
      remote: true,
      placeholder: '搜索选择项'
    },
    rules: [
      { required: true, message: '请选择发货单号', trigger: 'blur' },
      { validator: contactCodePass, trigger: 'change' }
    ]
  },
  {
    prop: 'invoiceFlag',
    label: '是否开红票',
    type: 'select',
    options: redTicketOpt,
    attr: {
      placeholder: '请选择'
    },
    rules: [
      { required: true, message: '请选择', trigger: 'change' }
    ]
  },
  {
    prop: 'returnAddressName',
    label: '收货地址',
    type: 'autocomplete',
    attr: {
      placeholder: '可选可输入',
      valueKey: 'label',
      maxlength: 98
    },
    rules: [
      { required: true, message: '请输入或选择收货地址', trigger: 'change' }
    ]
  },
  {
    prop: 'concatMan',
    label: '联系人',
    type: 'input',
    attr: {
      placeholder: '带入或输入',
      maxlength: 15
    },
    rules: [
      { required: true, message: '请输入联系人', trigger: 'change' }
    ]
  },
  {
    prop: 'concatPhone',
    label: '联系电话',
    type: 'input',
    attr: {
      placeholder: '带入或输入',
      maxlength: 11
    },
    rules: [
      { validator: contactNumberPass, required: true, trigger: 'change' }
    ]
  }
]
// 退货列表--列表表头
export const returnProductColumns = [
  { width: 40, type: 'selection' },
  { prop: 'itemCode', label: '产品编码', width: 170, 'show-overflow-tooltip': true },
  { prop: 'nameCn', label: '产品名称', width: 170, 'show-overflow-tooltip': true },
  { prop: 'specification', label: '规格', width: 170, 'show-overflow-tooltip': true },
  { prop: 'productType', label: '型号', width: 150 },
  { prop: 'minUnit', label: '最小单位', width: 150 },
  { prop: 'batchNumber', label: '批号', width: 150 },
  { prop: 'udi', label: 'UDI', width: 150 },
  { prop: 'num', label: '可退货数量', width: 150 },
  { prop: 'returnNum', label: '退货数量', width: 160 },
  { prop: 'price', label: '采购价格 （元）', width: 150, formatter: row => getFormatterPrice(row.price) },
  { prop: 'returnAmount', label: '小计金额 （元）', width: 150, formatter: row => getFormatterPrice(row.returnAmount) },
  { prop: 'registrationNumber', label: '注册证号', width: 150, 'show-overflow-tooltip': true },
  { prop: 'manufacturer', label: '生产厂家', width: 150, 'show-overflow-tooltip': true },
  {
    prop: 'category',
    label: '产品大类',
    width: 150,
    formatter: row => {
      return categoryArr[row.category]
    }
  },
  { prop: 'upCompanyProdCode', label: '配送商产品编码', 'min-width': 170, 'show-overflow-tooltip': true },
  { prop: 'action', label: '操作', width: 100, fixed: 'right' }
]

// 产品大类
export const categoryArr = {
  1: '高值',
  2: '低值',
  3: '试剂',
  4: '设备',
  5: '器械'
}
// 操作页-待响应-详情
export const addProductColumns = [
  { width: 40, type: 'selection' },
  { prop: 'itemCode', label: '产品编码', width: 150, 'show-overflow-tooltip': true },
  { prop: 'hospitalProductName', label: '产品名称', width: 150, 'show-overflow-tooltip': true }, // 1
  { prop: 'specification', label: '规格', width: 150, 'show-overflow-tooltip': true },
  { prop: 'productType', label: '型号', width: 150, 'show-overflow-tooltip': true },
  { prop: 'minUnit', label: '最小单位', width: 150 },
  { prop: 'price', label: '采购价格 （元）', width: 150, formatter: row => getFormatterPrice(row.price) },
  { prop: 'batch', label: '批号', width: 150 },
  { prop: 'udi', label: 'UDI', width: 150 },
  { prop: 'num', label: '可退货数量', width: 150 },
  {
    prop: 'registrationNumber',
    label: '注册证号/备案证号',
    width: 170,
    'show-overflow-tooltip': true
  },
  { prop: 'manufacturer', label: '生产厂家', width: 150, 'show-overflow-tooltip': true },
  { prop: 'deliveryCode', label: '配送商产品编码', width: 150, 'show-overflow-tooltip': true }
]
// 操作页-待响应-详情
export const addProductColumnsHasReceiveCode = [
  ...addProductColumns,
  { prop: 'receiveCode', label: '收货单号', width: 150, 'show-overflow-tooltip': true }
]
export const addSearchFormColumns = [
  {
    key: 'productCode',
    title: '产品编码',
    type: 'input',
    attr: {
      placeholder: '请输入',
      maxlength: 98
    }
  },
  {
    key: 'productName',
    title: '产品名称',
    type: 'input',
    attr: {
      placeholder: '请选择',
      filterable: true,
      maxlength: 98,
      remote: true
    }
  },
  {
    key: 'manufacturer',
    title: '生产厂家',
    type: 'input',
    attr: {
      placeholder: '请选择',
      maxlength: 98
    }
  },
  {
    key: 'productBatch',
    title: '批号',
    type: 'input',
    attr: {
      placeholder: '请输入',
      maxlength: 98
    }
  },
  {
    key: 'udi',
    title: 'UDI',
    type: 'input',
    attr: {
      placeholder: '请输入',
      maxlength: 98
    }
  }
]
